﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class GNParticles
    {
        private int xPos, yPos, particleX, particleY, spriteIndex = 0, dir;
        private Character c;

        public int SpriteIndex
        {
            get { return spriteIndex; }
            set { spriteIndex = value; }
        }

        private Sprite gNParticle = Sprites.CreateSprite(Resources.LoadBitmap(Resources.PathToResource("images\\Particle.png")), 10, 10, 3, 3);

        public Sprite GNParticle
        {
            get { return gNParticle; }
            set { gNParticle = value; }
        }

        public GNParticles(int xPos, int yPos, Character c)
        {
            this.c = c;
            ResetPosition(xPos, yPos);
        }

        public void Update(int xPos, int yPos)
        {
            particleX += (Core.Rnd(15) + 1)*-dir;
            particleY += (Core.Rnd(20 + GNParticle.CurrentCell * 2) - 10 - GNParticle.CurrentCell)*dir;

            if ((((particleX > 20 + (GNParticle.CurrentCell + 1) * 50 / 2) || (particleY > 20 + (GNParticle.CurrentCell + 1) * 50 / 2))
                || ((particleX < -20 - (GNParticle.CurrentCell + 1) * 50 / 2) || (particleY < 20 - (GNParticle.CurrentCell + 1) * 50 / 2)))
                    && (Core.Rnd() > 0.8))
                ResetPosition(xPos, yPos);
        }

        public void Draw()
        {
            gNParticle.Draw(xPos + particleX, yPos + particleY);
        }

        public void ResetPosition(int xPos, int yPos)
        {
            dir = c.DirectionMultiplier;
            particleX = (Core.Rnd(15) + 1)*-dir;
            particleY = (Core.Rnd(21) - 10)*-dir;
            this.xPos = xPos;
            this.yPos = yPos;
        }

        public void Free()
        {
            gNParticle.Dispose();
        }
    }
}
